﻿@{
}
@model Mango.Manager.ViewModels.ManagerPageViewModel

<table class="table">
    <tbody>
        <tr>
            <td>
                <input type="button" class="btn btn-success" id="btn_Add" value="添加分类" />
            </td>
        </tr>
    </tbody>
</table>
<table class="table table-hover table-list table-bordered table-sm">
    <thead>
        <tr>
            <th>Id</th>
            <th>分类名称</th>
            <th>排序</th>
            <th>是否显示</th>
            <th>操作</th>
        </tr>
    </thead>
    <tbody>
        @foreach (var row in Model.ListData)
        {
            <tr>
                <td>
                    @row["CId"]
                </td>
                <td>
                    @row["ClassifyName"]
                </td>
                <td>
                    @row["SortCount"]
                </td>
                <td>
                    @(row["IsShow"].ToString().ToLower()=="true"?"是":"否")
                </td>
                <td>
                    <a href="javascript:;" class="edit" data-name="@row["ClassifyName"]" data-id="@row["CId"]" data-sort="@row["SortCount"]" data-show="@row["IsShow"]">修改</a>
                    <a href="javascript:;" class="del" data-id="@row["CId"]">删除</a>
                </td>
            </tr>
        }
    </tbody>
</table>

<script type="text/javascript">
        //添加
        $("#btn_Add").click(function () {
            var html = '<form id="formAdd" method="post" action="/Navigation/AddClassify"><table class="table">';
            html += '<tr><td>分类名称:</td><td><input type="text" id="ClassifyName" name="ClassifyName" class="form-control" style="width:200px;" value=""></td></tr>';
            html += '<tr><td>排序:</td><td><input type="text" id="SortCount" name="SortCount" class="form-control" style="width:200px;" value=""></td></tr>';
            html += '<tr><td>是否显示:</td><td><select id="IsShow" name="IsShow"  class="form-control" style="width:200px;">';
            html += '<option value="true">是</option>';
            html += '<option value="false">否</option>';
            html += '</select></td></tr>';
            html += '</table></form>';
            layer.open({
                type: 1,
                title: '添加导航分类:',
                shadeClose: true,
                content: html,
                btn: ['保 存'],
                btn1: function () {
                    $("#formAdd").ajaxSubmit({
                        success: function (result) {
                            if (result) { 
                                ShowMessage('保存成功', '');
                            }
                        }
                    });
                }
            });
        });
        //修改数据
        $(".edit").click(function () {
            var id = $(this).attr("data-id");
            var name = $(this).attr("data-name");
            var isShow = $(this).attr("data-show");
            var sortCount = $(this).attr("data-sort");
            var html = '<form id="formEdit" method="post" action="/Navigation/EditClassify"><table class="table">';
            html += '<tr><td>分类名称:</td><td><input type="text" id="ClassifyName" name="ClassifyName" class="form-control" style="width:200px;" value="' + name + '"></td></tr>';
            html += '<tr><td>排序:</td><td><input type="text" id="SortCount" name="SortCount" class="form-control" style="width:200px;" value="' + sortCount + '"></td></tr>';
            html += '<tr><td>是否显示:</td><td><select id="IsShow" name="IsShow"  class="form-control" style="width:200px;">';
            html += '<option value="true">是</option>';
            html += '<option value="false">否</option>';
            html += '</select></td></tr>';
            html += '</table><input type="hidden" name="CId" id="CId" value="' + id + '" /></form>';
            layer.open({
                type: 1,
                title: '编辑导航分类:',
                shadeClose: true,
                content: html,
                btn: ['保 存'],
                btn1: function () {
                    $("#formEdit").ajaxSubmit({
                        success: function (result) {
                            if (result) {
                                ShowMessage('保存成功', '');
                            }
                        }
                    });
                }
            });
            $("#IsShow option[value='" + isShow + "']").attr("selected", true);
        });
        //删除数据
        $(".del").click(function () {
            var id = $(this).attr("data-id");
            //询问框
            layer.confirm('确认删除该记录？', {
                btn: ['确定', '取消'] //按钮
            }, function () {
                
                $.ajax({
                    type: 'post',
                    url: '/Navigation/DeleteClassify',
                    data: 'classifyId=' + id,
                    success: function (result) {
                        if (result) {
                            ShowMessage('删除成功', '');
                        }
                    }
                });
                }, function () {
                    return true;
            });

        });
</script>
